# 构建阶段
FROM node:18-alpine as build

# 设置工作目录
WORKDIR /app

# 设置淘宝 npm 镜像源以加快构建速度
RUN npm config set registry https://registry.npmmirror.com

# 复制 package.json 和 package-lock.json
COPY tutor-ui/package*.json ./

# 安装依赖
RUN npm install

# 复制源代码
COPY tutor-ui/src ./src
COPY tutor-ui/public ./public
COPY tutor-ui/index.html .
COPY tutor-ui/vite.config.js .
COPY tutor-ui/jsconfig.json .
COPY tutor-ui/static ./static

# 构建项目
RUN npm run build

# 生产阶段
FROM nginx:alpine

# 设置工作目录
WORKDIR /usr/share/nginx/html

# 删除默认的 nginx 静态文件
RUN rm -rf ./*

# 复制构建产物到 Nginx 目录
COPY --from=build /app/dist .

# 复制自定义的 nginx 配置
COPY tutor-ui/nginx.conf /etc/nginx/conf.d/default.conf

# 暴露端口
EXPOSE 80

# 启动 Nginx
CMD ["nginx", "-g", "daemon off;"] 